package com.qinhailin.portal.dbm.ctrl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import com.alibaba.fastjson.JSONArray;
import com.jfinal.aop.Clear;
import com.jfinal.aop.Inject;
import com.qinhailin.common.base.BaseController;
import com.qinhailin.common.routes.ControllerBind;
import com.qinhailin.common.util.AESUtil;
import com.qinhailin.portal.dbm.model.CTCustomer;
import com.qinhailin.portal.dbm.po.SessionKill;
import com.qinhailin.portal.dbm.po.SessionKilling;
import com.qinhailin.portal.dbm.service.CTCustomerServiceImpl;
import com.qinhailin.portal.dbm.service.DTSystemdataServiceImpl;

/**
 * 查询要杀死的线程
 * @author ward
 */
@ControllerBind(path="/portal/dbm/systemdata")
@Clear
public class SystemdataController extends BaseController{
	
	private static final Logger log = Logger.getLogger(SystemdataController.class);
	
	@Inject
	private CTCustomerServiceImpl customerService;
	@Inject
	private DTSystemdataServiceImpl systemdataService;
	
	public void index() {
		this.renderNull();
	}
/**
       1001 心跳间隔(毫秒)                                                                                                                                                                                                                                                        60000                                                                                                                                                                                                                                                                 60000                60000.0                60000 2019-12-28 13:06:45:630 2019-12-28 13:06:45:630           0 
       1002 语句执行超时(毫秒)                                                                                                                                                                                                                                                      300000                                                                                                                                                                                                                                                               300000               300000.0               300000 2019-12-28 13:06:45:670 2019-12-28 13:06:45:670           0 
       1003 系统名称                                                                                                                                                                                                                                                            数据库监控系统                                                                                                                                                                                                                                                                   0                    0.0                    0 2019-12-28 13:06:45:707 2019-12-28 13:06:45:707           0 
       1004 报表执行超时(秒)    
 */
	public void heartbeatInterval() {
		Integer rCustID = this.getInt();
		Integer result = 0;
		CTCustomer c = customerService.findByID(rCustID);
		if(c.getXHeartbeatInterval() != null && c.getXHeartbeatInterval() > 0)
			result = c.getXHeartbeatInterval();
		else
			result = systemdataService.findByID(1001).getXInt();
		this.renderJson(AESUtil.encrypt(result.toString(), c.getXKey()));
	}
	
	public void systemname() {
		Integer rCustID = this.getInt();
		CTCustomer c = customerService.findByID(rCustID);
		
		String name = systemdataService.findByID(1003).getXValue();
		if(name == null || name.contentEquals("")) {
			name="数据库监控系统";
		}
		this.renderJson(AESUtil.encrypt(name, c.getXKey()));
		
	}
		

}
